home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / LIB / FAKE_TOP.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  5.4 KB  |  169 lines

  1. package sub_arctic.lib;
  2.  
  3. import sub_arctic.lib.sub_arctic_error;
  4. import sub_arctic.output.drawable;
  5. import sub_arctic.output.style_manager;
  6. import sub_arctic.constraints.std_function;
  7.  
  8. import java.awt.Component;
  9. import java.awt.Point;
  10. import java.awt.Dimension;
  11. import java.awt.Rectangle;
  12. import java.awt.Image;
  13.  
  14. /** 
  15.  * This class creates a fake top_level object that can be hung inside another
  16.  * top_level object, but look to its subtree like the root.  This is 
  17.  * used to place an extra level between the real top and the actual tree,
  18.  * so that debugging lenses can be inserted without disturbing the tree.
  19.  * This object's parent <b>must</b> be a top_level object.  If it is placed
  20.  * anywhere else, various operations will crash.<p>
  21.  *
  22.  * Note: this has been partially obsoleted by the new applet/frame/etc. API
  23.  * which no longer hands out top_level objects and is set up for exactly this
  24.  * sort of interposing above the apparent root.  However, there are several
  25.  * interactors which have not be rewritten for that, so we keep this for now.
  26.  *
  27.  * @author Scott Hudson
  28.  */
  29. public class fake_top_level extends top_level {
  30.  
  31.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  32.  
  33.   /**
  34.    * Set the component that this this interactor is hosted in.  This gets
  35.    * forwarded to our parent, the real root object.
  36.    * @param Component par the hosting component
  37.    */
  38.   public void set_awt_parent(Component par) 
  39. {
  40.       if (parent() != null)
  41.         ((top_level)parent()).set_awt_parent(par);
  42.     }
  43.  
  44.    //had:
  45.    //* @exception general PROPAGATED
  46.  
  47.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  48.  
  49.   /**
  50.    * Return the AWT component which hosts this interactor.  This gets forwarded
  51.    * to our parent, the real root object. 
  52.    * @return Component the AWT component hosting this interactor
  53.    */
  54.   public Component awt_parent() 
  55.     {
  56.       if (parent() != null)
  57.         return ((top_level)parent()).awt_parent();
  58.       else
  59.     return null;
  60.      }
  61.  
  62.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  63.  
  64.   /**
  65.    * Construct a fake top_level object hosted by the given real top_level.
  66.    * This adds the constructed object to the given real parent and constrains
  67.    * itself to follow the size of the parent.
  68.    * @param top_level real_root the real root object we sit under
  69.    */
  70.   public fake_top_level(top_level real_root) 
  71. {
  72.       /* set us up at 0,0 with a temp size */
  73.       super(0,0,10,10);
  74.  
  75.       /* set our parent and constrain us to its size */
  76.       real_root.add_child(this);
  77.       set_w_constraint(std_function.offset(PARENT.W(), 0));
  78.       set_h_constraint(std_function.offset(PARENT.H(),0));
  79.     }
  80.  
  81.    //had:
  82.    //* @exception general PROPAGATED
  83.  
  84.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  85.  
  86.   /**
  87.    * Draw the image of this interactor (and its children) on the supplied
  88.    * drawable.  This reverts to normal interactor drawing behavior.
  89.    * @param drawable parent_d the drawable to render the image on
  90.    */
  91.   public void draw_self(drawable parent_d) 
  92. {
  93.       drawable local_d;
  94.  
  95.       /* we would just call super.super.draw_self(), but java does not allow
  96.        * that, so we had to copy this code from base_interactor. */
  97.  
  98.       /* damage will be fixed once we finish with this drawing */
  99.       damage_fixed();
  100.  
  101.       /* only draw if we are visible and trivial reject test indicates it 
  102.        * might actually appear */
  103.       if (visible() && !trivial_reject(parent_d))
  104.     {
  105.           /* save the graphics state and do the translation into local coords */
  106.           local_d = enter_local_coordinates(parent_d);
  107.  
  108.           /* do the actual drawing */
  109.           draw_self_local(local_d);
  110.  
  111.           /* restore the graphics state and undo the translation */
  112.           exit_local_coords(parent_d, local_d);
  113.     }
  114.     }
  115.  
  116.    //had:
  117.    //* @exception general PROPAGATED
  118.  
  119.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  120.  
  121.   /**
  122.    * Revert damage_self to original implementation. 
  123.    * @param Point top_left the upper left corner of the damaged area
  124.    * @param Dimension sz the size of the damaged area
  125.    */
  126.   public void damage_self(Point top_left, Dimension sz) 
  127. {
  128.       Point parent_tl;
  129.       interactor p;
  130.  
  131.       /* we would just call super.super.damage_self(), but java does not allow
  132.        * that, so we had to copy this code from base_interactor. */
  133.  
  134.       /* mark us as damaged */
  135.       set_flag_bit(DAMAGED);
  136.  
  137.       /* convert to parent's coords and tell them about it */
  138.       p = parent();
  139.       if (p != null)
  140.     {
  141.       /* put into coords of parent and pass damage up */
  142.           top_left.x = top_left.x + _x;
  143.           top_left.y = top_left.y + _y;
  144.       p.damage_from_child(top_left,sz);
  145.     }
  146.     }
  147.  
  148.    //had:
  149.    //* @exception general PROPAGATED
  150.  
  151.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  152. };
  153. /*=========================== COPYRIGHT NOTICE ===========================
  154.  
  155. This file is part of the subArctic user interface toolkit.
  156.  
  157. Copyright (c) 1996 Scott Hudson and Ian Smith
  158. All rights reserved.
  159.  
  160. The subArctic system is freely available for most uses under the terms
  161. and conditions described in 
  162.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  163. and appearing in full in the lib/interactor.java source file.
  164.  
  165. The current release and additional information about this software can be 
  166. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  167.  
  168. ========================================================================*/
  169.